package com.gosophia.metadataEngine.service.impl.test.integration;

import java.util.UUID;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;

import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.exception.ConcurrencyException;
import com.gosophia.metadataEngine.dao.DataSourceInfoDao;
import com.gosophia.metadataEngine.dao.MetaDataTableDao;
import com.gosophia.metadataEngine.entity.DataSourceInfo;
import com.gosophia.metadataEngine.entity.MetaDataTable;
import com.gosophia.metadataEngine.service.MetaDataTableService;
/**
 * MetaDataTableService集成测试
 * @author mayue
 *
 */
@ContextConfiguration(locations = { "classpath:applicationContext-it.xml",
"classpath*:moduleContext.xml" })
@TransactionConfiguration(defaultRollback= true)
public class ITMetaDataTableServiceImpl extends
        AbstractTransactionalJUnit4SpringContextTests {
    @Autowired
    private MetaDataTableService metaDataTableService;
    @Autowired
    private DataSourceInfoDao dataSourceInfoDao;
    
    @Autowired
    private MetaDataTableDao metaDataTableDao;
    @Test
    public void test(){
    	
    }
//    @Rollback(false)
//    @Test
//    public void testAddMetaDataTable() throws BusinessException{
//        String name = "名称"+UUID.randomUUID().toString();
//        MetaDataTable mdt = new MetaDataTable();
//        mdt.setTableName("T_USERMANA_USERINFO");
//        mdt.setTableNameCN("中文名"+UUID.randomUUID().toString());
//        mdt.setEntityClassName("实体类名"+UUID.randomUUID().toString());
//        DataSourceInfo dsi = dataSourceInfoDao.get(2L);
//        mdt.setDataSourceInfo(dsi);
//        metaDataTableService.addMetaDataTable(mdt);
//        MetaDataTable mdtAdd = metaDataTableDao.getUniqueByProperty("tableName", name);
//        Assert.assertEquals(name, mdtAdd.getTableName());
//        
//    }
//    @Test(expected= BusinessException.class)
//    public void testAddMetaDataTableRepeatName() throws BusinessException{
//        MetaDataTable mdt = new MetaDataTable();
//        mdt.setTableName("USERINFO");
//        mdt.setTableNameCN("用户信息表");
//        mdt.setEntityClassName("UserInfo");
//        DataSourceInfo dsi = dataSourceInfoDao.get(1L);
//        mdt.setDataSourceInfo(dsi);
//        metaDataTableService.addMetaDataTable(mdt);
//    }
//    @Test
//    public void testFindMetaDataTableById(){
//        MetaDataTable mdt = metaDataTableService.findMetaDataTableById(6L);
//        Assert.assertEquals("USERINFO", mdt.getTableName());
//    }
//    @Test
//    @Rollback(false)
//    @Test(expected = BusinessException.class)
//    public void testRemoveMetaDataTableUsed() throws BusinessException{
//        metaDataTableService.removeMetaDataTable(10000L,0L);
//    }
//    @Test(expected = ConcurrencyException.class)
//    public void testRemoveMetaDataTableNodata() throws BusinessException{
//        metaDataTableService.removeMetaDataTable(1000L,0L);
//    }
//    @Test
//    public void testUpdateMetaDataTable() throws BusinessException{
//        MetaDataTable mdt = metaDataTableDao.get(8L);
//        mdt.setTableName("修改名称");
//        metaDataTableService.updateMetaDataTable(mdt);
//        metaDataTableDao.clearEntityOnSession(mdt);
//        MetaDataTable mdt1 = metaDataTableDao.get(8L);
//        Assert.assertEquals("修改名称", mdt1.getTableName());
//    }
//    @Test(expected = BusinessException.class)
//    public void testUpdateMetaDataTableRepeatName() throws BusinessException{
//        MetaDataTable mdt = metaDataTableDao.get(7L);
//        mdt.setTableName("USERINFO");
//        metaDataTableService.updateMetaDataTable(mdt);
//        MetaDataTable mdt1 = metaDataTableDao.get(7L);
//        Assert.assertEquals("USERINFO", mdt1.getTableName());
//    }
//    @Test
//    public void testUpdateMetaDataTableSelf() throws BusinessException{
//        MetaDataTable mdt = metaDataTableDao.get(7L);
//        mdt.setTableName("修改");
//        metaDataTableService.updateMetaDataTable(mdt);
//        metaDataTableDao.clearEntityOnSession(mdt);
//        MetaDataTable mdt1 = metaDataTableDao.get(7L);
//        Assert.assertEquals("修改", mdt1.getTableName());
//    }
 
}
